package com.example.design_pattern.adapter;

import java.util.Enumeration;
import java.util.Iterator;

/**
 * 把Iterator转换成Enumeration的适配器
 */
public class IteratorToEnumAdapter<E> implements Enumeration<E> {

    private Iterator<E> iterator;

    public IteratorToEnumAdapter(Iterator<E> iterator) {
        this.iterator = iterator;
    }

    /**
     * Tests if this enumeration contains more elements.
     *
     * @return <code>true</code> if and only if this enumeration object
     * contains at least one more element to provide;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean hasMoreElements() {
        return iterator.hasNext();
    }

    /**
     * Returns the next element of this enumeration if this enumeration
     * object has at least one more element to provide.
     *
     * @return the next element of this enumeration.
     */
    @Override
    public E nextElement() {
        return iterator.next();
    }
}
